<!DOCTYPE html>
<html lang="zh_CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>兑换详情</title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- <link rel="shortcut icon" href="http://favicon.ico"> -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">

  <!--<link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">-->

  <!-- 固定的css 和 common.js 的引用    -->
  <link rel="stylesheet" href="https://gitee.com/huaflower/CommonTraderUnionFile/raw/master/css/sm.min.css">
  <link rel="stylesheet" href="https://gitee.com/huaflower/CommonTraderUnionFile/raw/master/css/sm-extend.min.css">
  <script type="text/javascript" src="https://gitee.com/huaflower/CommonTraderUnionFile/raw/master/common/js/common.js"></script>

  
  <style type="text/css">
    /*css 的样式都放在这里*/
    #content{
      background-color: white;
    }
    #first,#second,.third_margin,.third_margin_only,#fourth{
      padding-left: 3%;
      padding-right: 3%;
    }
    #first img{
      width: 100%;
    }
    #first{
      border-bottom: solid 8px #EDEBEB;
      padding-bottom: 10px;
      padding-top: 10px;
      text-align: center;
      /*border: solid 1px red;*/
    }
    #second{
      /*border: solid 1px red;*/
      /*border-bottom: solid 1px gainsboro;*/
    padding-bottom: 0.5rem;
    padding-top: 0.5rem;
    }
    #third{
      /*border: solid 1px red;*/
    }
    #third_a{
      /*padding-bottom: 10px;*/
      padding-top: 10px;
      /*border-bottom: solid 1px gainsboro;*/
      border-top: solid 1px #EDEBEB;
      margin-bottom: 2px;
      font-weight: 700;
    }
    /*文字*/
    .xiaobiaoti{
      font-weight: 700;
    }
    .miaoshu{
      font-size: 14px;
    }
    .third_margin{
      padding-bottom: 10px;
    }
    .duihuan_click{
      border-radius: 5px;
      color: white;
      text-align: center;
      padding-top: 10px;
      padding-bottom: 10px;
      margin-left: 15%;
      margin-right: 15%;
      display: none;
    }
    #jifenchongzu{
      background-color: #FC6107;
    }
    #jifenbuzu{
      background-color: gainsboro;
    }
    #fourth{
      margin-top: 1rem;
      padding-bottom: 2rem;
    }
    .miaoshu p{
      margin: auto;
    }
    #nickname{
      font-size: 18px;
      font-weight: 700;
    }
    #numjifen{
      color: red;
      font-size: 25px;
    }
    #priceshangpin{
      color: darkgray;
    /*text-decoration:line-through;*/
    }
    .page.page-current{
      overflow: auto;
    }

    #div_showaddress{
       position: fixed;
    top: 15%; /**顶部50%**/
    margin-top: -100px; /**上移-50%**/
    display: none;
    }

</style>


</head>
<body>
<div class="page-group">
  <div class="page page-current">
    <!-- html代码内容区域 -->

    <div class="content" id="div_showaddress" hidden>
      <div class="content" style = "background-color: black;opacity: 0.8;margin: 20px;"></div>
      <div class="list-block" style="margin-top: 50px;margin-left: 30px;margin-right: 30px;">
        <ul>
          <!-- Text inputs -->
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-name"></i></div>
              <div class="item-inner">
                <div class="item-title label">姓名</div>
                <div class="item-input">
                  <input type="text" placeholder="收件人" id="input_receiver">
                </div>
              </div>
            </div>
          </li>
        </ul>

        <!-- Text inputs -->
        <ul>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-name"></i></div>
              <div class="item-inner">
                <div class="item-title label">手机号</div>
                <div class="item-input">
                  <input type="text" placeholder="收件人手机号" id="input_mobile">
                </div>
              </div>
            </div>
          </li>
        </ul>

        <ul>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-name"></i></div>
              <div class="item-inner">
                <div class="item-title label">收件地址</div>
                <div class="item-input">
                  <input type="text" placeholder="请选择城市" readonly id="input_picker" >
                </div>
              </div>
            </div>
          </li>
        </ul>
        <!-- Text inputs -->
        <ul>
          <li>
            <div class="item-content">
              <div class="item-media"><i class="icon icon-form-name"></i></div>
              <div class="item-inner">
                <div class="item-title label">详细地址</div>
                <div class="item-input">
                  <textarea id="input_address"></textarea>
                  <!-- <input type="text" placeholder="收件地址" id="input_address"> -->
                </div>
              </div>
            </div>
          </li>
        </ul>
      </div>
      <div class="content-block" style = "margin-right: 30px;margin-left: 30px;">
        <div class="row">
          <div class="col-50"><div  id="buy_exit" onclick = "buy_exit()" class="button button-big button-fill button-danger">取消</div></div>
          <div class="col-50"><div id="buy_sure" onclick="buy_sure()" class="button button-big button-fill button-success">兑换</div></div>
        </div>
      </div>
    </div>


    <div id="content">
      <div id="first">
        <img src=""/>
      </div>
      <div id="second">
        <div id="nickname">
          <!--火龙果-->
        </div>
        <div id="price">
          <span id="numjifenadd">
            <!--<span id="numjifen">
              130
            </span>
            <span id="">
              积分
            </span>-->
          </span>
          <span id="priceshangpin" hidden>
            <!--￥13-->
          </span>
        </div>
      </div>
      <div id="third">
        <div id="third_a">
          <div id="" class="third_margin_only">
            描述详情
          </div>
        </div>
        <div id="" class="third_margin">
          <!--<div id="" class="xiaobiaoti">
            详情描述
          </div>-->
          <div id="miaoshuid" class="miaoshu">
            <!--商品介绍内容1234567890-->
          </div>
        </div>
        <!--<div id="" class="third_margin">
          <div id="" class="xiaobiaoti">
            使用有效期
          </div>
          <div id="" class="miaoshu">
            兑换1个月内有效
          </div>
        </div>
        <div id="" class="third_margin">
          <div id="" class="xiaobiaoti">
            兑换流程
          </div>
          <div id="" class="miaoshu">
            兑换介绍1234567890
          </div>
        </div>
        <div id="" class="third_margin">
          <div id="" class="xiaobiaoti">
            注意事项
          </div>
          <div id="" class="miaoshu">
            注意事项内容1234567890
          </div>
        </div>-->
      </div>
      <div id="fourth">
        <div id="jifenchongzu" class="duihuan_click" onclick="toonchange()">
          兑换
        </div>
        <div id="jifenbuzu" class="duihuan_click" hidden>
          积分不足
        </div>
      </div>




    </div>

  </div>
</div>





<!-- 固定的js引用，所有的jQuery 要用 $$ 表示 -->
<script type="text/javascript" src="https://gitee.com/huaflower/CommonScoreShop/raw/master/js/jquery-1.11.1.min.js"></script>
<!-- 这一行代码是为了 避免js冲突 -->
<script type="text/javascript">var $$ =jQuery.noConflict();</script>
<script type='text/javascript' src='https://gitee.com/huaflower/CommonScoreShop/raw/master/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='https://gitee.com/huaflower/CommonScoreShop/raw/master/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='https://gitee.com/huaflower/CommonScoreShop/raw/master/js/sm-extend.min.js' charset='utf-8'></script>
<script type="text/javascript" src="http://g.alicdn.com/msui/sm/0.6.2/js/sm-city-picker.min.js" charset="utf-8"></script>

<script type="text/javascript">
// 函数区域，函数放在“初始化区域的上面”
var chuanid;
var chuanscore;


var receiver = '';
var mobile = '';
var address = '';

  //一般app 初始化 html 传参数，函数名固定
    function getParams(data){

    var bb = JSON.parse(escape2Html(data));

    chuanid = bb.id;
    console.log(bb);
    if(isNotNull(bb.img)){
        $$("#first").html('<img src="'+bb.img+'"/>');
    }
    if(isNotNull(bb.detail)){
      $$("#miaoshuid").html(bb.detail);
    }
    if(isNotNull(bb.name)){
      $$("#nickname").html(bb.name);
    }
    if(isNotNull(bb.score)){
      $$("#numjifenadd").html('<span id="numjifen">'+bb.score+'</span><span id="">积分</span>&nbsp;&nbsp;&nbsp;&nbsp;');
      $$("#jifenchongzu").show();
        // if(Number(bb.score) <= Number(bb.userscore)){
        //   $$("#jifenchongzu").show();
        //   $$("#jifenbuzu").hide();
        //         }else{
        //         $$("#jifenbuzu").show();
        //         $$("#jifenchongzu").hide();
        //         }

        chuanscore = bb.score;
    }

    if(isNotNull(bb.redeem) && bb.redeem == '1'){
      $$("#numjifenadd").html('<span id="numjifen">1</span><span id="">提货券</span>&nbsp;&nbsp;&nbsp;&nbsp;');
      $$("#jifenchongzu").show();
       
    }
    
    if(isNotNull(bb.price)){
      $$("#priceshangpin").html("￥"+bb.price);
    }

  }

  //设置发货信息
  function setAddressInfo(data){

   /* var bb = $.parseJSON(data);
    $$('#input_receiver').val(bb.receiver);
    $$('#input_mobile').val(bb.mobile);
    $$('#input_address').val(bb.address);*/

var params = {
        callbacktype:'orderlist',
    };
    //网络请求框架，需要传入成功函数回调和 失败函数回调
    net_request('post','orderlist',params,successCallBack,errorCallBack);
  }

//取消
  function buy_exit(){

    $$("#div_showaddress").hide();

  }


//兑换
  function buy_sure(){

    receiver = $$('#input_receiver').val();
    mobile = $$('#input_mobile').val();
    city = $$('#input_picker').val();
    address = $$('#input_address').val();

    var straddress = address;
    if(address.indexOf(city) == -1){
      straddress = city +" "+ straddress;
    }

    if(isNotNull(receiver)){

        if(isNotNull(mobile) && mobile.length == 11){
            if(isNotNull(address) && isNotNull(city)){

            $$("#div_showaddress").hide();

              var params = {
                    callbacktype:'order',
                    product_id:chuanid+"",
                    mobile:mobile,
                    receiver:receiver,
                    address:straddress,
                    num:"1"
                  }
                  //网络请求框架，需要传入成功函数回调和 失败函数回调
                  net_request('post','order',params,successCallBack,errorCallBack);

            }else{
              $.toast('请填写收件地址和详细地址', 2000);
              return;
            }
        }else{
          $.toast('请填写正确的收件人手机号', 2000);
          return;
        }
    }else{
        $.toast('请填写收件人', 2000);
        return;
    }

  }


//  兑换接口
    function toonchange(){
//    alert("aa");

      $$("#div_showaddress").show();

  }
//  兑换成功回调
  function successCallBack(data){
    console.log(data);

        if(typeof(data) != "undefined" && data.callbacktype == 'order'){
            if(typeof(data) != "undefined"){
                if(data.state == '0' || data.state == 0){
                    native_showtoast("兑换成功，可在兑换记录中查看");
                }else{
                    native_showtoast(data.reason+"");
                }

            }else{
            //native_showtoast("兑换成功，可在兑换记录中查看");
                native_showtoast("兑换失败");
            }
        }else if(typeof(data) != "undefined" && data.callbacktype == 'orderlist'){
            var body = data.body;
            if(body.length > 0){
            $$('#input_receiver').val(body[0].receiver);
            $$('#input_mobile').val(body[0].mobile);
            $$('#input_address').val(body[0].address);
            }

        }



  }
//  兑换失败回调
    function errorCallBack(data){
    console.log(data);
  }


//  function toonchange(){
//      var params = {
//        product_id:3,
//        nu:1,
//        key:'随机数',
//        sign:'签名'
//    }
//    net_request('post','api/order',params,successCallBack_errors,errorCallBack_errors);
//  }
////  成功的回调函数
//  function successCallBack_errors(data){
//      console.log(data);
//  }
//
////  失败的回调函数
//  function errorCallBack_errors(data){
//    console.log(data);
//  }
    // 初始化区域
    $$(function () {
      //getParams();
        $$("#div_showaddress").hide();

        $("#input_picker").cityPicker({
            toolbarTemplate: '<header class="bar bar-nav">\
            <button class="button button-link pull-right close-picker">确定</button>\
            <h1 class="title">选择收货地址</h1>\
            </header>'
          });
        $.init();
    });

</script>
</body>
</html>